﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq; 
using System.Web.UI.MobileControls;
using Microsoft.JCI.Common.Utility;
using System.Collections.Generic;
using Microsoft.JCI.Bll;


namespace Microsoft.JCI.Portal.Branch
{
    public partial class Draft : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private List<SqlDbParameter> GetQueryCondition()
        {
            List<SqlDbParameter> listParameters = new List<SqlDbParameter>();
            SqlDbParameter Parameter = null;

            if (!string.IsNullOrEmpty(this.txtFormCode.Text.Trim()))
            {
                Parameter = new SqlDbParameter();
                Parameter.ColumnName = "FormCode";
                Parameter.ColumnType = DbType.String;
                Parameter.ParameterName = "@FormCode";
                Parameter.ParameterValue = this.txtFormCode.Text.Trim();
                Parameter.QualificationType = SqlDbParameter.QualificationSymbol.Like;
                listParameters.Add(Parameter);
            }

            if (!string.IsNullOrEmpty(this.txtFormCode.Text.Trim()))
            {
                Parameter = new SqlDbParameter();
                Parameter.ColumnName = "Name";
                Parameter.ColumnType = DbType.String;
                Parameter.ParameterName = "@Name";
                Parameter.ParameterValue = this.txtCustomerName.Text.Trim();
                Parameter.QualificationType = SqlDbParameter.QualificationSymbol.Like;
                listParameters.Add(Parameter);
            }

            if (!string.IsNullOrEmpty(this.txtFormCode.Text.Trim()))
            {
                Parameter = new SqlDbParameter();
                Parameter.ColumnName = "Mobile";
                Parameter.ColumnType = DbType.String;
                Parameter.ParameterName = "@Mobile";
                Parameter.ParameterValue = this.txtMobile.Text.Trim();
                Parameter.QualificationType = SqlDbParameter.QualificationSymbol.Like;
                listParameters.Add(Parameter);
            }

            if (this.dtFrom.SelectedDate.HasValue)
            {
                Parameter = new SqlDbParameter();
                Parameter.ColumnName = "CreateOn";
                Parameter.ColumnType = DbType.DateTime;
                Parameter.ParameterName = "@CreateOn";
                Parameter.ParameterValue = this.dtFrom.SelectedDate.Value;
                Parameter.QualificationType = SqlDbParameter.QualificationSymbol.GreaterAndEqual;
                listParameters.Add(Parameter);
            }

            if (this.dtTo.SelectedDate.HasValue)
            {
                Parameter = new SqlDbParameter();
                Parameter.ColumnName = "CreateOn";
                Parameter.ColumnType = DbType.DateTime;
                Parameter.ParameterName = "@CreateOn1";
                Parameter.ParameterValue = this.dtTo.SelectedDate.Value;
                Parameter.QualificationType = SqlDbParameter.QualificationSymbol.LessAndEqual;
                listParameters.Add(Parameter);
            }

            Parameter = new SqlDbParameter();
            Parameter.ColumnName = "FormStatus";
            Parameter.ColumnType = DbType.Int32;
            Parameter.ParameterName = "@FormStatus";
            Parameter.ParameterValue = (int)Enumerator.FormStatus.Draft;
            Parameter.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
            listParameters.Add(Parameter);

            Parameter = new SqlDbParameter();
            Parameter.ColumnName = "CreateBy";
            Parameter.ColumnType = DbType.String;
            Parameter.ParameterName = "@CreateBy";
            Parameter.ParameterValue = this.CurrentUserEntity.Account;
            Parameter.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
            listParameters.Add(Parameter);

            return listParameters;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            DispatchBll bll = new DispatchBll();
            DataTable dt = bll.QueryDispatchForm(GetQueryCondition());
            this.radGridCustomerList.DataSource = dt;
            radGridCustomerList.DataBind();
        }

        protected void radGridCustomerList_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
        {
            DispatchBll bll = new DispatchBll();
            DataTable dt = bll.QueryDispatchForm(GetQueryCondition());
            this.radGridCustomerList.DataSource = dt;
        }
    }
}
